package com.topisv.tms.service;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.topisv.tms.entity.ExpressStyle;
import com.topisv.tms.entity.LogisticsCompany;
import com.topisv.tms.repository.ExpressStyleDao;
import com.topisv.tms.repository.LogisticsCompanyDao;

@Component
@Transactional(readOnly = true)
public class ExpressStyleService {
	@Autowired
	private LogisticsCompanyDao logisticsCompanyDao;
	
	public List<ExpressStyle> findByCustomerCodeAndAreaGroupCode(String customerCode,String areaGroupCode){
		return expressStyleDao.findByCustomerCodeAndAreaGroupCode(customerCode, areaGroupCode);
	}
	public List<ExpressStyle> findByCustomerCodeAndAreaGroupCodeAndLogisticsCompanyId(String customerCode,String areaGroupCode,Long id){
		return expressStyleDao.findByCustomerCodeAndAreaGroupCodeAndLogisticsCompanyId(customerCode, areaGroupCode,id);
	}

	@Autowired
	public void setExpressStyleDao(ExpressStyleDao expressStyleDao) {
		if (expressStyleDao == null) {
			throw new IllegalArgumentException("expressStyleDao="
					+ expressStyleDao);
		}
		this.expressStyleDao = expressStyleDao;
	}

	private ExpressStyleDao expressStyleDao;
	
	public List<ExpressStyle> findStyle(String companyCode,String customerCode,String areaGroupCode){
		return expressStyleDao.findStyle(companyCode, customerCode, areaGroupCode);
	}
	public List<ExpressStyle> findStyleNew(String companyCode,String customerCode,String areaGroupCode,String type){
		if (StringUtils.isBlank(companyCode)) {
			return expressStyleDao.findStyleNew(customerCode, areaGroupCode, type);
		} else {
			return expressStyleDao.findStyleNew(companyCode, customerCode, areaGroupCode, type);
		}
	}
	public List<ExpressStyle> findStyleNew(String customerCode,String areaGroupCode,String type){
		return expressStyleDao.findStyleNew(customerCode, areaGroupCode,type);
	}
	
	public List<ExpressStyle> findByLogisticsCompanyAndAreaGroupCode(Long id,String areaGroupCode,String cainiaoFlg,String customerCode){
		LogisticsCompany logisticsCompany=logisticsCompanyDao.findOne(id);
		return expressStyleDao.findByLogisticsCompanyAndAreaGroupCode(logisticsCompany.getCompanyCode(), areaGroupCode,cainiaoFlg,customerCode);
	}
	
	public List<ExpressStyle> findByLogisticsCompanyAndAreaGroupCode(LogisticsCompany logisticsCompany,String areaGroupCode,String cainiaoFlg){
		return expressStyleDao.findByLogisticsCompanyAndAreaGroupCode(logisticsCompany.getCompanyCode(), areaGroupCode,cainiaoFlg,null);
	}

	public Iterable<ExpressStyle> findAll() {
		return expressStyleDao.findAll();
	}

	public List<ExpressStyle> findByStyleDufault(String customerCode) {
		return expressStyleDao.findByStyleDufault(customerCode);
	}
	
	public List<ExpressStyle> findByStyleDufault() {
		return expressStyleDao.findByStyleDufault();
	}

	
	public ExpressStyle findStyleDefault(Long logistics_company_id,String customerCode) {
		if (logistics_company_id == null) {
			throw new IllegalArgumentException("logistics_company_id="
					+ logistics_company_id);
		}
		return expressStyleDao.findStyleDefault(logistics_company_id,customerCode);
	}

	@Transactional(readOnly = false)
	public void deleteStyleDufault(Long expressStyleId) {
		if (expressStyleId == null) {
			throw new IllegalArgumentException("logistics_company_id="
					+ expressStyleId);
		}
		expressStyleDao.deleteStyleDufault(expressStyleId);
	}

	@Transactional(readOnly = false)
	public ExpressStyle saveExpressStyle(ExpressStyle expressStyle) {
		if (expressStyle == null) {
			throw new IllegalArgumentException("expressStyle=" + expressStyle);
		}
		return expressStyleDao.save(expressStyle);
	}

	@Transactional(readOnly = false)
	public void deleteExpressStyle(ExpressStyle expressStyle) {
		if (expressStyle == null) {
			throw new IllegalArgumentException("expressStyle=" + expressStyle);
		}
		expressStyleDao.delete(expressStyle);
	}

	@Transactional(readOnly = false)
	public void deleteExpressStyleId(Long expressStyleId) {
		if (expressStyleId == null) {
			throw new IllegalArgumentException("expressStyleId="
					+ expressStyleId);
		}
		expressStyleDao.delete(expressStyleId);
	}

	
	public List<ExpressStyle> findStyleNames(Long logistics_company_id) {
		if (logistics_company_id == null) {
			throw new IllegalArgumentException("logistics_company_id="
					+ logistics_company_id);
		}
		return expressStyleDao.findStyleNames(logistics_company_id);
	}

	@Transactional(readOnly = false)
	public ExpressStyle findOne(Long id) {
		if (id == null) {
			throw new IllegalArgumentException("id=" + id);
		}
		return expressStyleDao.findOne(id);
	}

	@Transactional(readOnly = false)
	public void updateStyleDufault(Long logistics_company_id,String customerCode) {
		if (logistics_company_id == null) {
			throw new IllegalArgumentException("logistics_company_id="
					+ logistics_company_id);
		}
		expressStyleDao.updateStyleDufault(logistics_company_id,customerCode);
	}

	@Transactional(readOnly = false)
	public void deleteLogisticsId(Long logisticsId) {
		if (logisticsId == null) {
			throw new IllegalArgumentException("logisticsId=" + logisticsId);
		}
		expressStyleDao.deleteLogisticsId(logisticsId);
	}

	
	public ExpressStyle findLogistics(Long logisticsId) {
		if (logisticsId == null) {
			throw new IllegalArgumentException("logisticsId=" + logisticsId);
		}
		return expressStyleDao.findLogistics(logisticsId);
	}
}
